// ==================================================================
// 描 述：
// 作 者：王征:D
// 创建时间：2019/05/28 19:15:25
// ==============================================================
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Yunchang;
using AutoChess;
using System.Text;
using Table.DataModel;
using Table.Blo;

namespace AutoChess
{
    public class ChessPokedexChessDetail : MonoBehaviour
    {
        public ChessPokedexPage ParentPage;
        public ACChessInfoPanel ChessInfoPanel;
        public GameObject[] BtnActive;
        public UIModelKit ModelKit;

        private TableAutoChessHero _tableData;
        public void ShowPanel(TableAutoChessHero tableData)
        {
            gameObject.SetActive(true);

            _tableData = tableData;

            SetModel();

            OnSelectStarLv(1);
        }

        public void HidePanel()
        {
            gameObject.SetActive(false);
        }

        public void SelectNext(bool next)
        {
            ParentPage.SelectNext(next);
        }

        public void OnSelectStarLv(int starLv)
        {
            var tableChess = AutoChessBlo.GetChessTable(_tableData.heroId, starLv);
            ChessInfoPanel.SetData(tableChess.chessId);
            
            var index = starLv - 1;
            BtnActive[0].SetActive(index == 0);
            BtnActive[1].SetActive(index == 1);
            BtnActive[2].SetActive(index == 2);
        }

        private void SetModel()
        {
            var tableModel = Table.Blo.TableSailorModelBlo.GetTableSailorModelByHeroIdAndAppearence(_tableData.heroId, 0);
            Vector3 offset = Vector3.zero;
            float scale = 1f;
            var dictModelOffset = Table.Blo.TableHeroModelDisplayOffsetBlo.GetTableHeroModelDisplayOffset(tableModel.ModelId);
            if (dictModelOffset != null)
            {
                if (!string.IsNullOrEmpty(dictModelOffset.heroFormationPosOffset))
                {
                    offset = CommonMethod.GetPosition(dictModelOffset.heroFormationPosOffset);
                }
                if (dictModelOffset.heroFormationPosScale > 0)
                {
                    scale = dictModelOffset.heroFormationPosScale;
                }
            }
            ModelKit.SetOffset(offset);
            ModelKit.SetModelScale(scale);
            ModelKit.SetModel(tableModel.ModelRes);
        }

        private void OnDestroy()
        {
            ModelKit.ClearModel();
        }
    }
}
